#ifndef FASTNET_CONNECTION_HH
#define FASTNET_CONNECTION_HH

#include "node.hh"
#include <iostream>

namespace brain {

    class Connection {
        float src_x, src_y, dst_x, dst_y;
        float weight;

    public:
        Connection (float src_x, float src_y, float dst_x, float dst_y, float weight)
        : src_x(src_x), src_y(src_y), dst_x(dst_x), dst_y(dst_y), weight(weight)
        {
        }

        Connection (Node a, Node b, float w)
        : Connection(a.get_x(), a.get_y(), b.get_x(), b.get_y(), w) 
        {
        }

        float get_src_x () const { return src_x; }
        float get_src_y () const { return src_y; }
        float get_dst_x () const { return dst_x; }
        float get_dst_y () const { return dst_y; }
        float get_weight() const { return weight;}

        Node get_src () const { return {src_x, src_y}; }
        Node get_dst () const { return {dst_x, dst_y}; }
        void set_weight(float w) { this->weight = w; }

        friend bool operator< (Connection const& a, Connection const& b) {
            if (a.src_x < b.src_x) return true;
            else if (a.src_x > b.src_x) return false;

            if (a.src_y < b.src_y) return true;
            else if (a.src_y > b.src_y) return false;

            if (a.dst_x < b.dst_x) return true;
            else if (a.dst_x > b.dst_x) return false;

            else if (a.dst_y < b.dst_y) return true;
            else return false;
        }

        friend std::ostream& operator<< (std::ostream& out, Connection const& c) {
            return out << "(" << c.src_x << "," << c.src_y << ") --> (" 
                    << c.dst_x << "," << c.dst_y << "): " << c.weight;
        }
    };

}

#endif
